// pages/userhome/address/address.js
var app = getApp();
Page({
  data: {

  },
  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    console.log(options)
    var order = JSON.parse(options.order)
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      order: order,
      pintuan: options.pintuan
    })
    console.info(that.data.pintuan);
    that.setData({
      balance: wx.getStorageSync("balance")
    })
    wx.request({
      url: app.globalData.url + 'getOrderDetails?orderId=' + that.data.order.orderId,
      method: "get",
      success: function (res) {
        var hisId = res.data.data.groupShoppingHis.hisId;
        wx.getSetting({
          success: res => {
            if (res.authSetting['scope.userInfo']) {
            } else {
              // 未授权，跳转到授权页面
              wx.reLaunch({
                url: '/pages/zcuslist/index?assem=1&orderId=' + that.data.orderId + '&share=1&type=2&groupShoppingId=' + hisId
              })
            }
          }
        });
        that.setData({
          currentOrder: res.data.data,
        });
      }
    })
    console.info(that.data.order.groupShoppingHis.endTime);
    var sdfDate = that.data.order.groupShoppingHis.endTime.replace(/\.|\-/g, "/");
    var totalSeconds = new Date(sdfDate) - new Date();
    var days = Math.floor(totalSeconds / (24 * 3600 * 1000));
    var leave1 = totalSeconds % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000));
    if (hours < 10) {
      hours = '0' + hours;
    }
    var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
    var minutes = Math.floor(leave2 / (60 * 1000));
    if (minutes < 10) {
      minutes = '0' + minutes;
    };
    that.setData({
      days: days,
      hours: hours,
      minutes: minutes,
    });
  },
  delOrder: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要取消吗？',
      success: function (sm) {
        if (sm.confirm) {
          // 用户点击了确定 可以调用取消订单的方法了
          wx.request({
            url: app.globalData.url + 'delOrder',
            method: 'GET',
            data: {
              orderId: e.target.dataset.ordid,
              userId: wx.getStorageSync("userId")
            },
            success: function (res) {
              wx.navigateBack({ // 返回首页
                delta: 1,
              })
            }
          });
        }
      }
    });
  }, 
  goLogistice: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: '/pages/logistics/logistics?expressCompanyCode=' + this.data.expressArray[e.currentTarget.dataset.index].expressCompanyCode + '&trackingNumber=' + this.data.expressArray[e.currentTarget.dataset.index].trackingNumber + '&expressCompany=' + this.data.expressArray[e.currentTarget.dataset.index].expressCompany + '&expressInfo=' + that.data.expressArray[index].expressInfo + '&thumbnailimage=' + e.currentTarget.dataset.thumbnailimage
    })

  },
  goLogisticeFromReturn: function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/pages/logistics/logistics?expressCompanyCode=' + that.data.afterSafeList[index].expressCompanyCode + '&trackingNumber=' + that.data.afterSafeList[index].trackingNumber + '&expressCompany=' + that.data.afterSafeList[index].expressCompany + '&expressInfo=' + that.data.afterSafeList[index].expressInfo + '&thumbnailimage=' + e.currentTarget.dataset.thumbnailimage
    })
  },
  //确认收获
  trueGet: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否已经收到货物',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: app.globalData.url + 'orderSigned',
            method: 'GET',
            data: {
              orderId: e.target.dataset.ordid,
              userId: wx.getStorageSync("userId")
            },
            success: function (res) {
              wx.navigateTo({
                url: '/pages/myOrder/myOrder?type=3'
              })
            }
          });
        }
      }
    });

  },
  goEvaluationt: function (e) {//去评价
    wx.navigateTo({
      url: '/pages/evaluationt/evaluationt?productid='+e.currentTarget.dataset.id
    })
  },
  goOut: function (e) {
    wx.request({
      url: app.globalData.url + 'getWareHouseByProduct',
      method: 'GET',
      data: {
        productId: e.currentTarget.dataset.pid,
      },
      success: function (res) {
        wx.showModal({
          title: '退换货地址',
          content: '联系人：' + res.data.data.linker + "\r\n电话：" + res.data.data.telephone +"\r\n地址："+res.data.data.address,
          success: function (res) {
            if (res.confirm) {
            } else {
            }
          }
        })
      }
    });

  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    
  },
  goRefund: function (e) {
    console.log(e.currentTarget.dataset.orderpoid);
    wx.navigateTo({
      url: '/pages/afterSaleCente/afterSaleCente?orderProductId=' + e.currentTarget.dataset.orderpoid
    })
  },
  onUnload: function () {
    // 页面关闭
  },
  /**
   * 跳转到产品详情
   */
  toProduct: function (res) {
    var productid = res.currentTarget.dataset.productid;
    wx.navigateTo({
      url: '/pages/productDetail/productDetail?productid=' + productid+'&type=2',
    })

  },

  // 弹出
  modal_s: function (e) {
    this.setData({
      choo_modal: "block",
      z: true,
      ordId: e.target.dataset.ordid,
      dis_n:"none"
    });
  },
  //消失
  modal_n: function () {
    this.setData({
      choo_modal: "none",
      z: false,
      dis_n: "block"
    });
  },
  radio: function (e) {
    var that = this;
    var radioValue = e.currentTarget.dataset.value;
    that.setData({
      radioValue: radioValue
    })
    console.info(radioValue);
    if (radioValue == 1) {
      that.setData({
        checked1: false,
        checked: true,
        ordid: e.currentTarget.dataset.ordid
      })
    }
    if (radioValue == 2) {
      that.setData({
        checked1: true,
        checked: false,
        ordid: e.currentTarget.dataset.ordid
      })
    }
  },
  rePinTuan: function () {
    var that = this
    var plist = '[{"productId":"' + that.data.order.groupShoppingHis.product.productId + '","num":' + that.data.order.groupShoppingHis.groupShoppingNum + ',"price":' + that.data.order.groupShoppingHis.price + ',"title":"' + that.data.order.groupShoppingHis.product.title + '","thumbnailImage":"' + that.data.order.groupShoppingHis.product.thumbnailImage + '","point":' + that.data.order.groupShoppingHis.product.point + '}]';
      //此处跳转到修改订单页面
      that.setData({
        pAndNList: plist,
      })
        wx.navigateTo({
          url: '/pages/confirmOrder/confirmOrder?userId=' + wx.getStorageSync("userId") + '&pAndNList=' + that.data.pAndNList + '&type=2' 
        })
      
  },
  navBack: function () {
    wx.navigateBack({

    })
  }
})